-
-
Notifications
You must be signed in to change notification settings - Fork 391
Limit CodeActions within passed range #1442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
d33f980
to
e6c866f
Compare
Does the fix work? Could you please add a test? |
It does work, I'm writing the tests but I'm stuck because I can't write the following:
Any pointer? |
Nevermind, I'm dumb. I should map it with |
Should we audit the other instances of |
6e5553e
to
cd1580c
Compare
@berberman |
if numHintsInDoc > 1 then do | ||
if numHintsInRange > 1 then do | ||
pure $ applyAllAction:applyOneActions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should make sure that applyAllAction
is not always prepended to applyOneActions
, rather than changing numHintsInDoc
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it okay since it's only used to determine if we should prepend to applyOneActions
? And since I add more filtering, numHintsInRange <= numHintsInDoc
is always true so the condition in the change already includes numHintsInDoc > 1
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I just I realized that Apply all hints
does not mean applying all hints for those range, but it means applying all the hints in doc. I've changed the condition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should show applyAllAction
iff:
- there are more than one hlint diagnostics in the document
- there is at least one hlint diagnostic in the current code action context
right? So based on numHintsInDoc
, which has already implemented the logic for the first condition, you just need take a look at diagnostics in the current code action context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I tried just adding not (null diags)
and it works. The problem now is that lsp-test sends all the diagnostics instead of only those within range.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be wrong, but my understanding here is:
They are provided so that the server knows which errors are currently presented to the user for the given range
The client gives us the diagnostics that is shown to the user. If in the meantime the diagnostics changes, shouldn't the client issue the request again? We don't know for sure if the new diagnostics changes is already shown to the user (or even received by the client) and we might suggest actions that mismatch with what the user sees.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no guarantee that these accurately reflect the error state of the resource. The primary parameter to compute code actions is the provided range.
IMO this is the key bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but I'm not sure if this is possible:
- Client receives and shows diagnostic
dA
- Client issues code action request with
dA
as context - New diagnostic
dB
is sent from the server - Server sends code action based on
dB
(since it's latest state) - Client receives only code action suggestion but not the diagnostic message from (3) (maybe it's lost or something?)
In this case client will show diagnostic dA
with code action dB
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, consider that AFAICT this is not mandatory, so if a client simply hasn't implemented adding the extra diagnostics, then this feature will not work, despite us having access to a perfectly good range we can use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think they're optional? The definition doesn't have ?
in the name.
727607e
to
3471a28
Compare
3471a28
to
ca92689
Compare
, validCommand d | ||
, Just nfp == docNfp | ||
] | ||
numHintsInContext = length | ||
[d | d <- diags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this also assuming that the diagnostics we in the context are exclusively hlint hints? I'm pretty sure that's not true: you could get other warnings or errors as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got the impression that validCommand
checks that, is it not the case?
Return only actions within range specified by client.
f0796d1
to
cadeb78
Compare
@berberman I've rebased the changes since we're already using lsp-test 0.14.0.0. The test passed now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks!
Return only actions within range specified by client.
Fixes: #1341